package com.riccardocardin.structured.concurrency.application;

import com.riccardocardin.structured.concurrency.service.GitHubUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutionException;

import static com.riccardocardin.structured.concurrency.model.Model.GitHubUser;
import static com.riccardocardin.structured.concurrency.model.Model.UserId;

public class GitHubUserSyncAppService implements GitHubUserApplicationService {

    private static final Logger LOGGER = LoggerFactory.getLogger("GitHubApp");

    private final GitHubUserService gitHubUserService;

    public GitHubUserSyncAppService(GitHubUserService gitHubUserService) {
        this.gitHubUserService = gitHubUserService;
    }

    @Override
    public GitHubUser findGitHubUser(UserId userId) throws InterruptedException, ExecutionException {
        var user = gitHubUserService.findUser(userId);
        var repositories = gitHubUserService.findRepositories(userId);
        return new GitHubUser(user, repositories);
    }
}
